package com.threeox.commonlibrary.util;

import android.content.Intent;

import com.threeox.utillibrary.util.IntentUtils;
import com.threeox.utillibrary.util.LogUtils;
import com.threeox.utillibrary.util.java.ReflectUtil;

import java.util.Map;

/**
 *
 * @ClassName: ValueUtils
 *
 * @Description: TODO(取值的一个工具类)
 *
 * @author 赵屈犇
 *
 * @date 创建时间: 2017/9/8 13:45
 *
 * @version 1.0
 *
 */
public class ValueUtils {

    private static final String TAG = "ValueUtils";

    /**
     * 根据对象和Key值得到指定的数据
     *
     * @param data
     * @param key
     * @return
     */
    public static Object getObjValue(Object data, String key) {
        try {
            if (data instanceof Map) {
                return JSONUtils.getJSONValue((Map) data, key);
            } else if (data instanceof Intent) {
                return IntentUtils.get((Intent) data, key);
            } else {
                return ReflectUtil.getValue(data, key);
            }
        } catch (Exception e) {
            LogUtils.e(TAG, "getObjValue报错了:" + e.getMessage());
        }
        return null;
    }

    /**
     *
     * @ClassName: ValueUtils
     *
     * @Description: TODO()
     *
     * @author 赵屈犇
     *
     * @date 创建时间: 2017/12/18 10:03
     *
     * @version 1.0
     *
     */
    public static void putObjValue(Object data, String key, Object value) {
        try {
            if (data instanceof Map) {
                JSONUtils.putJSONValue((Map) data, key, value);
            } else if (data instanceof Intent) {
                IntentUtils.get((Intent) data, key);
            } else {
                ReflectUtil.setObjectValue(data, key, value);
            }
        } catch (Exception e) {
            LogUtils.e(TAG, "getObjValue报错了:" + e.getMessage());
        }
    }

}
